<template>
  <div class="login">
    <div>登录页</div>
    <input type="text" placeholder="输入手机号" v-model="formData.phone" style="padding-left:20px">
    <input type="password" placeholder="输入密码" v-model="formData.pass" style="padding-left:20px">
    <input type="submit" value="登录" @click="login" class="btn">
  </div>
</template>

<script>
import { user_login } from '@/utils/api';
export default {
   data(){
    return {
      formData:{
        phone:'',
        pass:''
      }
    }
  },
  methods:{
    login(){
     if(/^1[3-9]\d{9}$/.test(this.formData.phone)==false){
      alert('请输入合法的手机号');
    }else {
        user_login({phone:this.formData.phone,pass:this.formData.pass}).then((res)=>{
        if(res.data.msg=="登陆成功!"){
          localStorage.setItem('userinfo',JSON.stringify(res.data.userinfo));
          localStorage.setItem('token',res.data.token);
          this.$router.push('/index/mine');
        }
      })
    }
    }
  }


}
</script>

<style>
.login div{
  font-size: 16px;
  font-weight: bold;
  text-align: center;
  margin-top: 40px;
}
.login input{
  margin-left: 70px;
  height: 30px;
  margin-top: 10px;
  background-color: #E3E4E5;
  border: none;
  border-radius: 30px;
  width: 240px;
}
.login .btn{
  background-color: burlywood;
  text-align: center;
}
</style>